﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommunicationProtocol.dto.command.server
{
    public class PlantBuyableStatusResp : Command
    {
        public short objectId { get; }
        public short remainingMillisecond { get; }

        public string currentOwnerId { get; }

        public PlantBuyableStatusResp(byte[] remainingData) : base(103)
        {
            objectId = BitConverter.ToInt16(remainingData, 0);
            remainingMillisecond = BitConverter.ToInt16(remainingData, 2);
            currentOwnerId = Encoding.UTF8.GetString(remainingData, 4, remainingData.Length - 4);
        }

        /**
         *  remainingMillisecond
         *  -1 当前植物被 currentOwnerId 所持有
         *  0 可以购买当前植物
         *  >0 当前植物的冷却事件（毫秒）
         */
        public PlantBuyableStatusResp(short objectId, short remainingMillisecond, string currentOwnerId) :base(103)
        {
            this.objectId = objectId;
            this.remainingMillisecond = remainingMillisecond;
            this.currentOwnerId = currentOwnerId;
        }

        public override byte[] GetBytes()
        {
           
            return new byte[] {
                functionCode,
            }.Concat(BitConverter.GetBytes((short)objectId))
            .Concat(BitConverter.GetBytes((short)remainingMillisecond))
            .Concat(Encoding.UTF8.GetBytes(currentOwnerId))
            .ToArray();
        }
    }
}
